#include "rpc.h"
#include "usr_proc.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

void * svc_read_file(void * fun_data)
{
	char name[12] = {0};
	char buf[16] = {0};
	int len = 0;
	MY_DATA req_data;
	static MY_DATA reply_data;
	memset(&req_data, 0, sizeof(MY_DATA));
	memset(&reply_data, 0, sizeof(MY_DATA));

	memcpy(&req_data, (MY_DATA*)fun_data, sizeof(MY_DATA));
	
	strncpy(name, req_data.name, sizeof(req_data.name));
	len = req_data.len;
	printf("len: %d,data_len:%d\n", len, req_data.len);
	int fd = open(name, O_RDONLY);
	read(fd, buf, len);
	close(fd);

	buf[len] = '\0';
	printf("name:%s,len:%d,buf:%s.\n", name, len, buf );

	strncpy(req_data.buf, buf, len);

	memcpy(&reply_data, &req_data, sizeof(MY_DATA));

	return &reply_data;
}
#ifdef  MAKESVC
int main(int argc, char const *argv[])
{
	rpc_svc_run();
	return 0;
}
#endif
